/**   
 * @Title: SportteryFootballFaqiHemaiAct.java 
 * @Package com.esun.rabbit2.viewer.mainact.lotteryhallact.sportteryfootballapg 
 * @Description: (竞彩足球,发起合买) 
 * @author: City Jiangsy@500wan.com   
 * @date: 2011-8-26 下午03:26:46  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.viewer.mainact.lotteryhallact.sportteryfootballapg;

import java.text.DecimalFormat;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.esun.config.Config;
import com.esun.config.Language;
import com.esun.model.UserInfo;
import com.esun.model.sportteryfootball.SportteryFootballLotteryInfo;
import com.esun.rabbit2.communicaters.sportteryfootball.SportteryFootballHemaiLannchCommunicater;
import com.esun.rabbit2.viewer.LoginAct;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.HelpAct;
import com.esun.rabbit2.viewer.mainact.mylotteryact.recharg.RechargeMenuPage;
import com.esun.ui.R;
import com.esun.util.LoginTimeControl;
import com.esun.util.ViewerUtil;
import com.esun.util.log.EDebug;

/**
 * @ClassName: SportteryFootballFaqiHemaiAct
 * @Description: (竞彩足球,发起合买)
 * @author: City Jiangsy@500wan.com
 * @date: 2011-8-26 下午03:26:46
 * 
 */
public class SportteryFootballFaqiHemaiAct extends Activity implements OnClickListener, OnCheckedChangeListener {
	private EditText edtHemaiPartCount;
	private EditText edtHemaiTicheng;
	private EditText edtHemaiRengou;
	private EditText edtHemaiBaodi;

	private Button btnHemaiSubmit;
	private ImageButton btnHemaiCancel;
	private ImageButton btnHemaiHelp;

	private TextView tvHemaiMoneyEach;
	private TextView tvHemaiRengou;
	private TextView tvBaodiPercent;
	private TextView tvRengouPercent;
	private TextView tvBaodiMoney;
	private LinearLayout linearBaodi;

	private CheckBox cbxIsBaodi;

	private Handler handlerHemai;

	private long allNum; // 总份数
	private long buyNum; // 认购份数 ,不低于总份数5%,不高于总份数
	private long baodiNum; // 保底份数,占总份数不低于20%
	private int tichengNum; // 0,1,2,3,4,5,6,7,8,9,10 0为缺省值
	private boolean isBaodi;

	private int zhushu;
	private int beishu;
	private long allMoney;
	private int guoguanType;
	private String codes;
	private String sgtype;

	private double eachMoney; // 每份金额,保留小数点后两位

	private ProgressDialog progressdialogHemai;

	private boolean isRightAllNum = true;
	private boolean isRightBuyNum = true;
	private boolean isRightBaodiNum = true;
	private LoginTimeControl loginTimeControl;

	private Dialog dialogBuySucceed;

	private SportteryFootballHemaiLannchCommunicater sportteryFootballHemaiLannchCommunicater;
	private static final int BUY_SUCCEED = 11001;
	private static final int BUY_FAIL = 11002;
	
	
	public static final int RESULT_CODE_CONTINUE_BUY = 1;
	public static final int RESULT_CODE_BACK_TO_HALL = 2;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sportteryfootball_faqihemai_act);
		initUi();
		edtHemaiPartCount.requestFocus();
		initHandler();
	}

	private void initUi() {
		// TODO Auto-generated method stub
		edtHemaiPartCount = (EditText) findViewById(R.id.sportteryfootballfaqihemaiact_edt_fenshuCount);
		edtHemaiTicheng = (EditText) findViewById(R.id.sportteryfootballfaqihemaiact_edt_ticheng);
		edtHemaiRengou = (EditText) findViewById(R.id.sportteryfootballfaqihemaiact_edt_rengou);
		edtHemaiBaodi = (EditText) findViewById(R.id.sportteryfootballfaqihemaiact_edt_baodi);

		btnHemaiSubmit = (Button) findViewById(R.id.sportteryfootballfaqihemaiact_btn_submit);
		btnHemaiCancel = (ImageButton) findViewById(R.id.sportteryfootballfaqihemaiact_btn_cancel);
		btnHemaiHelp = (ImageButton) findViewById(R.id.sportteryfootballfaqihemaiact_btn_help);

		btnHemaiSubmit.setOnClickListener(this);
		btnHemaiCancel.setOnClickListener(this);
		btnHemaiHelp.setOnClickListener(this);

		tvHemaiMoneyEach = (TextView) findViewById(R.id.sportteryfootballfaqihemaiact_tv_eachMoney);
		tvHemaiRengou = (TextView) findViewById(R.id.sportteryfootballfaqihemaiact_tv_buyMoney);

		tvBaodiPercent = (TextView) findViewById(R.id.sportteryfootballfaqihemaiact_tv_baodiPercent);
		tvRengouPercent = (TextView) findViewById(R.id.sportteryfootballfaqihemaiact_tv_rengouPercent);
		tvBaodiMoney = (TextView) findViewById(R.id.sportteryfootballfaqihemaiact_tv_baodiMoney);

		cbxIsBaodi = (CheckBox) findViewById(R.id.sportteryfootballfaqihemaiact_cbx_isBaodi);
		cbxIsBaodi.setOnCheckedChangeListener(this);

		linearBaodi = (LinearLayout) findViewById(R.id.sportteryfootballfaqihemaiact_linear_baodi);
		linearBaodi.setVisibility(View.INVISIBLE);

		// edtHemaiBaodi.setEnabled(false);
		// edtHemaiBaodi.setFocusable(false);

		allNum = 1;
		buyNum = 1;
		baodiNum = 0;
		tichengNum = 0;
		isBaodi = false;

		zhushu = SportteryFootballLotteryInfo.getSportteryFootballLotteryInfo().getZhushuCount();
		beishu = SportteryFootballLotteryInfo.getSportteryFootballLotteryInfo().getMultiple();
		allMoney = (long) zhushu * (long) beishu * 2;
		guoguanType = SportteryFootballLotteryInfo.getSportteryFootballLotteryInfo().getGuoguanType();
		codes = SportteryFootballLotteryInfo.getSportteryFootballLotteryInfo().getCodes();
		sgtype = SportteryFootballLotteryInfo.getSportteryFootballLotteryInfo().getSgType();

		progressdialogHemai = ViewerUtil.showProgressDialog(this, Language.POPLOTTERYTIP_BUYING);
		loginTimeControl = new LoginTimeControl();
		updateViewSet();
		editTextWatcherAdd();
		updateEdtInfo();
		sportteryFootballHemaiLannchCommunicater = new SportteryFootballHemaiLannchCommunicater();
	}

	private void updateViewSet() {
		// TODO Auto-generated method stub

		tvHemaiMoneyEach.setText(Language.POPLOTTERYTIP_RMB + getDoubleString(eachMoney));
		if (allNum > allMoney) {
			isRightAllNum = false;
			tvHemaiMoneyEach.setText(Language.STR_QINGSHURU + Config.NUM1 + Config.HORIZONTAL_LINE + Long.toString(allMoney)
					+ Language.STR_ZHIJIANDESHUZI);
			tvHemaiMoneyEach.setTextColor(getResources().getColor(R.color.dark_red));
		} else if (allNum < 1) {
			isRightAllNum = false;
			tvHemaiMoneyEach.setText(Language.STR_QINGSHURU + Config.NUM1 + Config.HORIZONTAL_LINE + Long.toString(allMoney)
					+ Language.STR_ZHIJIANDESHUZI);
			tvHemaiMoneyEach.setTextColor(getResources().getColor(R.color.dark_red));
		} else if ((allMoney * 100) % allNum == 0 && (allMoney * 100) / allNum >= 100) {
			isRightAllNum = true;
			eachMoney = (allMoney * 100) / allNum;
			tvHemaiMoneyEach.setText(Language.POPLOTTERYTIP_RMB + getDoubleString(eachMoney));
			tvHemaiMoneyEach.setTextColor(getResources().getColor(R.color.dark_red));
		} else {
			isRightAllNum = false;
			tvHemaiMoneyEach.setText(Language.STR_BUNENGBEIZHENGCHU);
			tvHemaiMoneyEach.setTextColor(getResources().getColor(R.color.dark_red));
		}

		if (buyNum > allNum) {
			isRightBuyNum = false;
			tvHemaiRengou.setText(Language.POPLOTTERYTIP_RMB + getDoubleString(eachMoney * buyNum));
			tvRengouPercent.setText(Language.STR_QINGSHURU + Long.toString(getRengouLower(allNum)) + Config.HORIZONTAL_LINE + Long.toString(allNum)
					+ Language.STR_ZHIJIANDESHUZI);
			tvRengouPercent.setTextColor(getResources().getColor(R.color.dark_red));
		} else if (buyNum < getRengouLower(allNum)) {
			isRightBuyNum = false;
			tvHemaiRengou.setText(Language.POPLOTTERYTIP_RMB + getDoubleString(eachMoney * buyNum));
			tvRengouPercent.setText("认购份数不能低于总份数的5%");
			tvRengouPercent.setTextColor(getResources().getColor(R.color.dark_red));
		} else {
			isRightBuyNum = true;
			tvHemaiRengou.setText(Language.POPLOTTERYTIP_RMB + getDoubleString(eachMoney * buyNum));
			tvRengouPercent.setText(Config.LEFT_ROUND_BR + getDoubleString((double) (buyNum * 10000 / allNum)) + Config.PERCENT
					+ Config.RIGHT_ROUND_BR);
			tvRengouPercent.setTextColor(getResources().getColor(R.color.dark_red));
		}
		if (isBaodi) {
			if (baodiNum > allNum) {
				isRightBaodiNum = false;
				tvBaodiMoney.setText(Language.POPLOTTERYTIP_RMB + getDoubleString(eachMoney * baodiNum));
				tvBaodiPercent.setText(Language.STR_QINGSHURU + Long.toString(getBaodiLower(allNum)) + Config.HORIZONTAL_LINE + Long.toString(allNum)
						+ Language.STR_ZHIJIANDESHUZI);
				tvBaodiPercent.setTextColor(getResources().getColor(R.color.dark_red));
			} else if (baodiNum < getBaodiLower(allNum)) {
				isRightBaodiNum = false;
				tvBaodiMoney.setText(Language.POPLOTTERYTIP_RMB + getDoubleString(eachMoney * baodiNum));
				tvBaodiPercent.setText("保底份数不能低于总份数的20%");
				tvBaodiPercent.setTextColor(getResources().getColor(R.color.dark_red));
			} else {
				isRightBaodiNum = true;
				tvBaodiMoney.setText(Language.POPLOTTERYTIP_RMB + getDoubleString(eachMoney * baodiNum));
				tvBaodiPercent.setText(Config.LEFT_ROUND_BR + getDoubleString((double) (baodiNum * 10000 / allNum)) + Config.PERCENT
						+ Config.RIGHT_ROUND_BR);
				tvBaodiPercent.setTextColor(getResources().getColor(R.color.solid_black));
			}

		} else {
			isRightBaodiNum = true;
			// tvBaodiMoney.setText(Config.NULLMARK);
			tvBaodiPercent.setText(Config.NULLMARK);
		}

	}

	private void updateEdtInfo() {
		edtHemaiTicheng.setText(Integer.toString(tichengNum));
		edtHemaiPartCount.setText(Long.toString(allNum));
		edtHemaiRengou.setText(Long.toString(buyNum));
		edtHemaiBaodi.setText(Long.toString(baodiNum));
	}

	private void editTextWatcherAdd() {
		edtHemaiPartCount.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				// TODO Auto-generated method stub
				if (!(String.valueOf(s).equals(Config.NULLMARK)) && s != null) {
					allNum = Long.parseLong(String.valueOf(s));
					Toast partCountToast = Toast.makeText(SportteryFootballFaqiHemaiAct.this, Language.STR_QINGSHURU + Config.NUM1
							+ Config.HORIZONTAL_LINE + Long.toString(allMoney) + Language.STR_ZHIJIANDESHUZI, Toast.LENGTH_SHORT);
					partCountToast.setGravity(Gravity.CENTER, 0, 0);
					if (allNum > allMoney) {
						allNum = allMoney;
						partCountToast.show();
						edtHemaiPartCount.setText(Long.toString(allNum));
					} else if (allNum < 1) {
						allNum = 1;
						partCountToast.show();
					} else if ((allMoney * 100) % allNum == 0 && (allMoney * 100) / allNum >= 100) {
						eachMoney = (allMoney * 100) / allNum;
					} else {
						EDebug.o(SportteryFootballFaqiHemaiAct.this, "noDivisible");
					}
				} else {
					isRightAllNum = false;
					allNum = 1;
				}
				updateViewSet();

			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {
				// TODO Auto-generated method stub

			}

			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub

			}
		});
		edtHemaiTicheng.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				// TODO Auto-generated method stub
				if (edtHemaiTicheng.hasFocus()) {
					if (!(String.valueOf(s).equals(Config.NULLMARK)) && s != null) {
						tichengNum = Integer.parseInt(String.valueOf(s));
						if (tichengNum > 8) {
							Toast tichengToast = Toast.makeText(SportteryFootballFaqiHemaiAct.this, Language.STR_QINGSHURU + Config.NUM0
									+ Config.HORIZONTAL_LINE + Integer.toString(8) + Language.STR_ZHIJIANDESHUZI, Toast.LENGTH_SHORT);
							tichengToast.setGravity(Gravity.CENTER, 0, 0);
							tichengToast.show();
							tichengNum = 8;
							edtHemaiTicheng.setText(Integer.toString(tichengNum));
						}
					} else {
						tichengNum = 0;
					}
					updateViewSet();
				}
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {
				// TODO Auto-generated method stub

			}

			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub

			}
		});
		edtHemaiRengou.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				// TODO Auto-generated method stub
				if (edtHemaiRengou.hasFocus()) {
					if (!(String.valueOf(s).equals(Config.NULLMARK)) && s != null) {
						buyNum = Integer.parseInt(String.valueOf(s));
						Toast rengouToast = Toast.makeText(SportteryFootballFaqiHemaiAct.this,
								Language.STR_QINGSHURU + Long.toString(getRengouLower(allNum)) + Config.HORIZONTAL_LINE + Long.toString(allNum)
										+ Language.STR_ZHIJIANDESHUZI, Toast.LENGTH_SHORT);
						rengouToast.setGravity(Gravity.CENTER, 0, 0);
						if (buyNum > allNum) {
							rengouToast.show();
							buyNum = allNum;
							edtHemaiRengou.setText(Long.toString(buyNum));
						} else if (buyNum < getRengouLower(allNum)) {
							rengouToast.show();
						}
					} else {
						buyNum = getRengouLower(allNum);
					}
					updateViewSet();
				}
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {
				// TODO Auto-generated method stub

			}

			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub

			}
		});

		edtHemaiBaodi.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				// TODO Auto-generated method stub
				if (edtHemaiBaodi.hasFocus() && cbxIsBaodi.isChecked()) {
					if (!(String.valueOf(s).equals(Config.NULLMARK)) && s != null) {
						Toast baodiToast = Toast.makeText(SportteryFootballFaqiHemaiAct.this,
								Language.STR_QINGSHURU + Long.toString(getBaodiLower(allNum)) + Config.HORIZONTAL_LINE + Long.toString(allNum)
										+ Language.STR_ZHIJIANDESHUZI, Toast.LENGTH_SHORT);
						baodiToast.setGravity(Gravity.CENTER, 0, 0);

						baodiNum = Integer.parseInt(String.valueOf(s));
						if (baodiNum < getBaodiLower(allNum)) {
							baodiToast.show();

						} else if (baodiNum > allNum) {
							baodiToast.show();
							baodiNum = allNum;
							edtHemaiBaodi.setText(Long.toString(baodiNum));
						} else {

						}
					} else {
						baodiNum = getBaodiLower(allNum);
					}
					updateViewSet();
				}
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {
				// TODO Auto-generated method stub

			}

			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub

			}
		});
	}

	private void initHandler() {
		// TODO Auto-generated method stub
		handlerHemai = new Handler() {
			public void handleMessage(Message msg) {
				progressdialogHemai.dismiss();
				switch (msg.what) {
				case BUY_SUCCEED:
					buySucceed();
					break;

				case BUY_FAIL:
					if (sportteryFootballHemaiLannchCommunicater.getState() == 0) {
//						ViewerUtil.showTipDialog(SportteryFootballFaqiHemaiAct.this, sportteryFootballHemaiLannchCommunicater.getErrorMSG()
//								+ Config.COMMA + Language.POPLOTTERYTIP_LOOKOVERRECORD, false);
						Toast.makeText(SportteryFootballFaqiHemaiAct.this,sportteryFootballHemaiLannchCommunicater.getErrorMSG()+ Config.COMMA + Language.POPLOTTERYTIP_LOOKOVERRECORD , 0).show();
					} else if (sportteryFootballHemaiLannchCommunicater.getState() == 105) {
						popBalanceNotEnoughAlert();
					} else {
					  
						//ViewerUtil.showTipDialog(SportteryFootballFaqiHemaiAct.this, sportteryFootballHemaiLannchCommunicater.getErrorMSG(), false);
					  Toast.makeText(SportteryFootballFaqiHemaiAct.this, sportteryFootballHemaiLannchCommunicater.getErrorMSG(), 0).show();
					}
					break;
				case Config.CONNECTION_FAIL:
//					ViewerUtil.showTipDialog(SportteryFootballFaqiHemaiAct.this, Language.STR_CONNECTIONFAIL + Config.COMMA
//							+ Language.POPLOTTERYTIP_LOOKOVERRECORD, false);
					Toast.makeText(SportteryFootballFaqiHemaiAct.this, Language.STR_CONNECTIONFAIL + Config.COMMA + Language.POPLOTTERYTIP_LOOKOVERRECORD, 0).show();
					break;
				default:
					break;
				}
			}
		};

	}

	private void buySucceed() {
		if (dialogBuySucceed == null) {
			dialogBuySucceed = new Dialog(this, R.style.dialog);
		}
		dialogBuySucceed.setContentView(R.layout.viewerutil_dialog_showbuysucceed);
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_msg)).setText("发起合买成功");
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_count)).setText("认购:" + buyNum + "份");
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_cost)).setText("消费:"
				+ Language.POPLOTTERYTIP_RMB + getDoubleString(eachMoney * buyNum));
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_balance)).setText("剩余金额:"
				+ Language.POPLOTTERYTIP_RMB + UserInfo.getUserInfo().getUserBalance());
		dialogBuySucceed.show();
		OnClickListener dialogSucceedListener = new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.viewerutildialogshowbuysucceed_btn_back:
					dialogBuySucceed.dismiss();
					SportteryFootballFaqiHemaiAct.this.finish();
					SportteryFootballChooseAct.pageFlag = 0;
					Message msg = SportteryFootballChooseList.handlerChoosePage.obtainMessage(SportteryFootballChooseList.DO_REFRESH, null);
					SportteryFootballChooseList.handlerChoosePage.sendMessage(msg);
					break;

				case R.id.viewerutildialogshowbuysucceed_btn_toHall:
					dialogBuySucceed.dismiss();
					SportteryFootballFaqiHemaiAct.this.finish();
					SportteryFootballChooseAct.pageFlag = -1;
					Message msgFinish = SportteryFootballChooseList.handlerChoosePage.obtainMessage(SportteryFootballChooseList.DO_FINISH,null);
					SportteryFootballChooseList.handlerChoosePage.sendMessage(msgFinish);
					break;
				default:
					break;
				}
				SportteryFootballLotteryInfo.getSportteryFootballLotteryInfo().getLotterList().clear();

			}
		};
		((Button) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_btn_back)).setOnClickListener(dialogSucceedListener);
		((Button) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_btn_toHall))
				.setOnClickListener(dialogSucceedListener);
		dialogBuySucceed.setOnDismissListener(new OnDismissListener() {

			@Override
			public void onDismiss(DialogInterface dialog) {
				// TODO Auto-generated method stub
				SportteryFootballFaqiHemaiAct.this.finish();
			}
		});

	}

	private Dialog dialogBalanceNotEnough;
	private View.OnClickListener moneyNotEnoughListener;

	private void popBalanceNotEnoughAlert() {
		if (dialogBalanceNotEnough == null) {
			dialogBalanceNotEnough = new Dialog(this, R.style.dialog);
		}

		if (moneyNotEnoughListener == null) {
			moneyNotEnoughListener = new OnClickListener() {

				@Override
				public void onClick(View v) {
					switch (v.getId()) {
					case R.id.shiyixuanwu_alert_money_not_enough_btn_cancel:
						break;

					case R.id.shiyixuanwu_alert_money_not_enough_btn_recharge:
						UserInfo.getUserInfo().setBuyingRecharge(true);

						SportteryFootballFaqiHemaiAct.this.startActivity(new Intent().setClass(SportteryFootballFaqiHemaiAct.this,
								RechargeMenuPage.class));

						break;
					}

					dialogBalanceNotEnough.dismiss();
				}
			};
		}

		View view = this.getLayoutInflater().inflate(R.layout.shiyixuanwu_alert_money_not_enough, null);

		((Button) view.findViewById(R.id.shiyixuanwu_alert_money_not_enough_btn_cancel)).setOnClickListener(moneyNotEnoughListener);
		((Button) view.findViewById(R.id.shiyixuanwu_alert_money_not_enough_btn_recharge)).setOnClickListener(moneyNotEnoughListener);

		dialogBalanceNotEnough.setContentView(view);
		dialogBalanceNotEnough.show();
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.sportteryfootballfaqihemaiact_btn_submit:
			if (UserInfo.getUserInfo().getUserSession().length() < 3) {
				Intent intent = new Intent();
				intent.setClass(SportteryFootballFaqiHemaiAct.this, LoginAct.class);
				startActivity(intent);
			} else {
				hemaiSubmit();
			}
			break;

		case R.id.sportteryfootballfaqihemaiact_btn_cancel:
			SportteryFootballFaqiHemaiAct.this.finish();
			break;

		case R.id.sportteryfootballfaqihemaiact_btn_help:

			Intent intentToHelp = new Intent();
			intentToHelp.setClass(SportteryFootballFaqiHemaiAct.this, HelpAct.class);
			intentToHelp.putExtra("url", Config.WHATIS_HEMAI_WEB_ADD).putExtra("title", "合买介绍").putExtra("havetitle", Config.NUM1);
			startActivity(intentToHelp);
			break;
		default:
			break;
		}

	}

	private void hemaiSubmit() {
		// TODO Auto-generated method stub
		if (edtHemaiPartCount.getText().equals(null) || edtHemaiPartCount.getText().toString().equals(Config.NULLMARK)
				|| edtHemaiRengou.getText().equals(null) || edtHemaiRengou.getText().toString().equals(Config.NULLMARK)
				|| edtHemaiBaodi.getText().equals(null) || edtHemaiBaodi.getText().toString().equals(Config.NULLMARK)) {
			ViewerUtil.showTipDialog(SportteryFootballFaqiHemaiAct.this, Language.STR_QINGWANZHENGTIANXIE, false);
		} else {
			if (!isRightAllNum || !isRightBaodiNum || !isRightBuyNum) {
				EDebug.o(SportteryFootballFaqiHemaiAct.this, "isRightAllNum= " + isRightAllNum + " isRightBaodiNum= " + isRightBaodiNum
						+ " isRightBuyNum= " + isRightBuyNum);
				ViewerUtil.showTipDialog(SportteryFootballFaqiHemaiAct.this, Language.STR_QINGYUEDUTISHI, false);
			} else if (loginTimeControl.isNeedInputPwd()) {
				loginTimeControl.showInputPasswordDialog(this);
			} else {
				progressdialogHemai.show();
				threadHemai();
			}
		}

	}

	/** 工具类,待合并 */
	private String getDoubleString(double _eachMoney) {
		_eachMoney = _eachMoney / 100;
		DecimalFormat format = new DecimalFormat("0.00");
		format.setMaximumFractionDigits(3);
		String result = format.format(_eachMoney);
		return result;
	}

	private Long getBaodiLower(Long betCount) {
		long baodiLower = 0;
		if (betCount % 5 == 0) {
			baodiLower = betCount / 5;
		} else {
			baodiLower = (betCount / 5) + 1;
		}
		return baodiLower;
	}

	private Long getRengouLower(long betCount) {
		long regouLower = 0;
		if (betCount % 20 == 0) {
			regouLower = betCount / 20;
		} else {
			regouLower = (betCount / 20) + 1;
		}
		return regouLower;
	}

	private void threadHemai() {
		new Thread() {
			@Override
			public void run() {
				super.run();
				try {
					EDebug.o(SportteryFootballFaqiHemaiAct.this, " thread go ");
					EDebug.o(SportteryFootballFaqiHemaiAct.this, " zhushu = " + zhushu + " bieshu = " + beishu + " allMoney = " + allMoney
							+ " guoguanType = " + guoguanType + " allNum = " + allNum + " buyNum " + buyNum + " baodiNum = " + baodiNum
							+ " tichengNum = " + tichengNum + " codes = " + codes + " sgtype = " + sgtype + " isbaodi = " + isBaodi);
					boolean b = sportteryFootballHemaiLannchCommunicater.isBuySucceed(zhushu, beishu, allMoney, guoguanType, allNum, buyNum,
							baodiNum, tichengNum, codes, sgtype, isBaodi);
					EDebug.o(SportteryFootballFaqiHemaiAct.this, " thread goon ");
					if (b) {
						Message msg = handlerHemai.obtainMessage(BUY_SUCCEED, null);
						handlerHemai.sendMessage(msg);
					} else {
						Message msg = handlerHemai.obtainMessage(BUY_FAIL, null);
						handlerHemai.sendMessage(msg);
					}
				} catch (Exception e) {
					// TODO: handle exception
					Message msg = handlerHemai.obtainMessage(Config.CONNECTION_FAIL, null);
					handlerHemai.sendMessage(msg);
				}
			}
		}.start();
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		// TODO Auto-generated method stub
		isBaodi = isChecked;
		if (isChecked) {
			linearBaodi.setVisibility(View.VISIBLE);
			// edtHemaiBaodi.setEditable();
		} else {
			linearBaodi.setVisibility(View.INVISIBLE);
			baodiNum = 0;
		}
		updateViewSet();
	}
}
